package cvslogic.elements;

import util.AuxiliaryFunctions;
import util.Constants;

import com.pavelvlasov.uml.Classifier;
import com.pavelvlasov.uml.Element;
import com.pavelvlasov.uml.Model;
import com.pavelvlasov.uml.ModelElement;

public class ComparePackage {

	private CompareElement compareElement = new CompareElement();
	private CompareModelElement compareModelElement = new CompareModelElement();
	private CompareActor compareActor = new CompareActor();
	private CompareClassifier compareClassifier = new CompareClassifier();
	private CompareTagged compareTagged = new CompareTagged();

	public void compareVersions(Model newVersion, Model oldVersion) {
		Object[] newPackages = newVersion.getPackages().toArray();
		Object[] oldPackages = oldVersion.getPackages().toArray();

		comparePackages(newPackages, oldPackages);
	}

	public void comparePackages(Object[] newPackages, Object[] oldPackages) {

		for (Object newPackage : newPackages) {
			Element oldPackage = AuxiliaryFunctions.getByID(oldPackages,
					newPackage);

			if (oldPackage != null) {
				System.out.println(" Package: " + oldPackage.getName());
				compareElement.compareProperties((Element) oldPackage,
						(Element) newPackage);
				compareModelElement.compareProperties(
						(ModelElement) oldPackage, (ModelElement) newPackage);
				System.out.println(Constants.EOF + " Actors");
				compareActor.compareActors(((Classifier) newPackage)
						.getElements(Constants.ACTOR, null).toArray(),
						((Classifier) oldPackage).getElements(Constants.ACTOR,
								null).toArray());

			}
			System.out.println("---");

			comparePackages(((Classifier) newPackage).getElements(
					Constants.PACKAGE, null).toArray(),
					((Classifier) oldPackage).getElements(Constants.PACKAGE,
							null).toArray());

		}

	}
}
